﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;

namespace TestMvc.Controllers
{
    public class TestAsyncController : AsyncController
    {
        //
        // GET: /TestAsync/

        public ActionResult Index()
        {
            return Content("1");
        }

        public void testAsync()
        {
            AsyncManager.OutstandingOperations.Increment();
            AsyncManager.Parameters["result"] = 1;
            AsyncManager.OutstandingOperations.Decrement();
        }

        public ActionResult testCompleted(int result)
        {
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        public JsonResult test2()
        {
            var task = Task.Factory.StartNew(() => true).
            ContinueWith(t =>
            {
                return Json(t,JsonRequestBehavior.AllowGet);
            });
            return task.Result;
        }
    }
}
